/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import sg.edu.nus.iss.pacman.manager.webservice.WebServiceClientManager;
import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;

/**
 *
 * @author Tabiul Mahmood
 */
public class DownloadMazeList extends TextBox implements CommandListener {

    private static final String TITLE = "Download Map List";
    private static final String MESSAGE = "Please wait...\nLoading map list";
    private PacManMIDlet mainApp;
    private String message;
    private Command cmdCancel;

    /**
     * Constructor for this screen
     *
     * @param mainApp PacManMIDlet
     */
    public DownloadMazeList(PacManMIDlet mainApp) {
        super(TITLE, MESSAGE, MESSAGE.length(), TextField.UNEDITABLE);
        this.message = MESSAGE;
        this.mainApp = mainApp;
        init();
    }

    /**
     * Initializes the screen
     */
    private void init() {
        cmdCancel = new Command(PacManMIDlet.LABEL_CMD_CANCEL, Command.CANCEL, 1);

        addCommand(cmdCancel);
        setCommandListener(this);
        WebServiceClientManager manager = new WebServiceClientManager(
            mainApp.getServerURL(), mainApp);
        manager.retrieveMapListing();

    }

    /**
     * This is a method which handles command actions
     */
    public void commandAction(Command cmd, Displayable dept) {
        if (cmd == cmdCancel) {
            mainApp.displayMainMenu();
        }
    }
}
